home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 15 / BBS in a box XV-2.iso / Files II / Prog / U-Z / UltraShell Demo 1.1.sit / UltraShell™ Demo V1.1 / ExampleExternalCommand / cmp.c next >
Encoding:
C/C++ Source or Header  |  1994-10-26  |  1.9 KB  |  91 lines  |  [TEXT/KAHL]

  1. /* Version B */
  2.  
  3. /*===========================================================\
  4. |                     UltraShell (tm)                        |
  5. |                                                            |
  6. |                         cmp.c                              |
  7. |   This program performs a binary comparison of two files,  |
  8. |      and returns a value of 0 to indicate that they are    |
  9. |       the same. If identical, it also prints "same"        |
  10. |         to stdout; if not, it prints "different".          |
  11. |                    from UltraShell.                        |
  12. |                                                            |
  13. |           Copyright (C) 1994 by Zack T. Smith              |
  14. |                                                            |
  15. |     Permission is granted to freely distribute this        |
  16. |    file. The data contained herein may be adapted to       |
  17. |       whatever tasks are at hand, so long as they          |
  18. |             involve the use of UltraShell.                 |
  19. \===========================================================*/
  20.  
  21.  
  22. #include <stdio.h>
  23.  
  24. #include "ucommand.h"
  25.  
  26.  
  27.  
  28. main ()
  29. {
  30.     char *argv[100];
  31.     int ch, ch2;
  32.     FILE *f1, *f2;
  33.     int same = 1;
  34.     long argc;
  35.     
  36.     if (!(argc = ucommand (argv, 100)))
  37.     {
  38.         printf ("No shell information found.\n");
  39.         shell_exit (2);
  40.     }
  41.     
  42.     /* Usage for 'cmp' is 'cmp file1 file2'
  43.      * Here we verify that we have 3 args.
  44.      */
  45.     if (argc != 3)
  46.         shell_exit (4);
  47.  
  48.     f1 = fopen (argv[1], "r");
  49.     if (!f1)
  50.     {
  51.         fprintf (shell_stderr, "Unable to open %s.\n", argv[1]);
  52.         shell_exit (5);
  53.     }
  54.     
  55.     f2 = fopen (argv[2], "r");
  56.     if (!f2)
  57.     {
  58.         fprintf (shell_stderr, "Unable to open %s.\n", argv[2]);
  59.         shell_exit (5);
  60.     }
  61.     
  62.     do
  63.     {
  64.         ch = fgetc (f1);
  65.         ch2 = fgetc (f2);
  66.         
  67.         if (ch != ch2)
  68.         {
  69.             same = 0;
  70.             break;
  71.         }
  72.         
  73.         if (ch == EOF)
  74.             break;
  75.     }
  76.         while(1);
  77.     
  78.     if (same)
  79.     {
  80.         fprintf (shell_stdout, "same\n");
  81.         shell_exit (0);
  82.     }
  83.     else
  84.     {
  85.         fprintf (shell_stdout, "different\n");
  86.         shell_exit (1);
  87.     }
  88. }
  89.  
  90.  
  91.